import axios from 'axios';
import React from 'react';
import { useParams } from 'react-router-dom';
import { Button } from 'react-vant';

const Index: React.FC = () => {
  // 订单号
  const orderID = 23456789098765432;
  // 订单金额
  // const price = 400.00;00
  // 订单标题
  // const title = '住宿费'
  const { price, title } = useParams()

  const handlePayment = async () => {
    // 调用支付接口， 获取支付的链接
    const resp = await axios.post('/api/pay/zfb', { orderID, price, title });
    // 打开链接
    window.location.href = resp.data.data
    console.log(resp)
  }
  return (
    <div>
      <h3>订单号: { orderID }</h3>
      <h3>订单金额: ¥{ price }</h3>
      <h3>订单标题: { title }</h3>
      <Button type="primary" block onClick={() => handlePayment()}>立即付款</Button>
    </div>
  );
};

export default Index;
